#include "ShapeModel.h"
#include <QBrush>
#include <QIcon>

ShapeModel::ShapeModel(QObject *parent): QAbstractListModel(parent)
{
}

ShapeModel::~ShapeModel()
{
}

int ShapeModel::rowCount(const QModelIndex &parent) const
{
	if (parent.isValid())
	{
		return 0;
	}
	else
	{
		return pixmaps.size();
	}
}

QVariant ShapeModel::data(const QModelIndex &index, int role) const
{
	if (!index.isValid())
		return QVariant();

	if (role == Qt::DecorationRole)
		return QIcon(pixmaps.value(index.row()).scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation));
	else if (role == Qt::DisplayRole)
		return QString("Cube");
	/*
	else if (role == Qt::BackgroundRole)
	{
		if (index.row() & 1)
			return QBrush(QColor(Qt::red));
		else
			return QBrush(QColor(Qt::blue));
	}
	*/



	return QVariant();
}

Qt::ItemFlags ShapeModel::flags(const QModelIndex &index) const
{
	if (index.isValid()) 
	{
		return (Qt::ItemIsEnabled | Qt::ItemIsSelectable| Qt::ItemIsDragEnabled | Qt::ItemIsSelectable);
	}

	return Qt::ItemIsEnabled | Qt::ItemIsDropEnabled;
}

void ShapeModel::AddShape(const QPixmap &pixmap)
{
	int row;

	row = pixmaps.size();

	beginInsertRows(QModelIndex(), row, row);

	pixmaps.insert(row, pixmap);

	endInsertRows();
}
